<?php

namespace app\controllers;

use Yii;
use yii\base\Exception;
use yii\data\ActiveDataProvider;
use app\com\simtoon\log\LogUtils;
/**
 * 2015-10-07 add by hetao
 * 地图找房数据，序列化类
 */
class SerializerMapToJson implements SerializerModels{

    public function parseJson($result){
        try{
            $res = array("status"=>1,"msg"=>"查询失败!");
            if(count($result) > 0){
                $res['status'] = 0;
                if($result == '1' || $result == '0') {
                    $res['res'] = $result;
                }else if($result == '-1'){
                    $res['msg'] = '操作失败!';
                }else{
                    $model = $result['models'];
                    if(count($model) > 0){
                        foreach ($model as $key => $value) {
                            $arr = array();
                            foreach($value as $k=>$v){
                                $arr[$k] = $v;
                            }
                            $array[$key] = $arr;
                        }
                        $res['result'] = $array;
                        $res['stamp'] = $result['stamp'];
                        $res['msg'] = "";
                    }else{
                        $res['result'] = array();
                        $res['status'] = 0;
                        $res['msg'] = "";
                        $res['stamp'] = $result['stamp'];
                    }
                    if(array_key_exists("house",$result)){
                        $house = $result['house']['result'];
                        if(count($house) > 0){
                            foreach ($house as $key => $value) {
                                $arr = array();
                                foreach($value as $k=>$v){
                                    $arr[$k] = $v;
                                }
                                $array[$key] = $arr;
                            }
                            $res['house'] = $array;
                            $res['pageCount'] = $result['house']['totalCount'];
                            $res['pageNow'] = $result['house']['pageNow'];
                            $res['pageSize'] = $result['house']['pageSize'];
                            $res['stamp'] = $result['stamp'];
                            $res['msg'] = "";
                        }else{
                            $res['house'] = array();
                        }
                    }
                }
            }
            else if(count($result) === 0){
                $res['status'] = 0;
                $res['msg'] = "";
                $res['result'] = array();
            }

            $ss =  json_encode($res);
            die($ss);
        }catch (Exception $e){
            LogUtils::error($e->getMessage(), __METHOD__);
            die(json_encode($res));
        }
    }

}

?>